package com.lxw.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    public static final String EXCHANGE_TOPIC = "exchange_topic";
    public static final String QUEUE_EMAIL = "queue_email";
    public static final String ROUTING_EMAIL = "routing.#.email.#";
    public static final String QUEUE_SMS = "queue_sms";
    public static final String ROUTING_SMS = "routing.#.sms.#";

    @Bean(EXCHANGE_TOPIC)
    public Exchange getExchange(){
        return ExchangeBuilder.topicExchange(EXCHANGE_TOPIC).durable(true).build();
    }

    @Bean(QUEUE_EMAIL)
    public Queue getQueueEmail(){
        Queue queue = new Queue(QUEUE_EMAIL);
        return queue;
    }
    @Bean(QUEUE_SMS)
    public Queue getQueueSms(){
        Queue queue = new Queue(QUEUE_SMS);
        return queue;
    }

    @Bean
    public Binding binding_email(@Qualifier(QUEUE_EMAIL) Queue queue, @Qualifier(EXCHANGE_TOPIC) Exchange exchange){
       return BindingBuilder.bind(queue).to(exchange).with(ROUTING_EMAIL).noargs();
    }
    @Bean
    public Binding binding_sms(@Qualifier(QUEUE_SMS) Queue queue,@Qualifier(EXCHANGE_TOPIC) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(ROUTING_SMS).noargs();
    }
}
